package main

import "fmt"

func aaa() func(int) int {
	var num = 10
	return func(i int) int {
		num = num + i
		return num
	}

}

// 匿名函数
func main() {
	result := func(a int, b int) int {
		return a + b
	}(10, 20)
	fmt.Println(result)

	sum := func(a int, b int) int {
		return a + b
	}
	result2 := sum(10, 20)
	fmt.Println(result2)
	result3 := sum(30, 40)
	fmt.Println(result3)

	//函数闭包
	f := aaa()
	fmt.Println(f(1))
	fmt.Println(f(1))
}
